<!DOCTYPE html>
<html lang="en-us">
<head><head>
    <meta name="google-site-verification" content="9vIieCe-Qpd78QOmBl63rGtIVbhY6sYyuxX3j8XWBA4" />
    <meta name="baidu-site-verification" content="LRrmH41lz7" />
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="description" content="docker部署zabbix，graphtree">
    
    <meta name="keyword"  content=", , 马少勋的网络日志, 马少勋的博客, Mashaoxun Blog, 博客, 个人网站, 互联网, Web, 云原生, PaaS, Istio, Kubernetes, 微服务, Microservice">
    <link rel="shortcut icon" href="/blog/img/favicon.ico">

    <title>docker部署zabbix-马少勋的博客 | MaShaoXun Blog</title>

    <link rel="canonical" href="/blog/2019/05/28/docker-zabbix-install/">

    <link rel="stylesheet" href="/blog/css/iDisqus.min.css"/>
	
    
    <link rel="stylesheet" href="/blog/css/bootstrap.min.css">

    
    <link rel="stylesheet" href="/blog/css/hux-blog.min.css">

    
    <link rel="stylesheet" href="/blog/css/syntax.css">

    
    <link rel="stylesheet" href="/blog/css/zanshang.css">

    
    <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    
    
    <script src="/blog/js/jquery.min.js"></script>
    
    
    <script src="/blog/js/bootstrap.min.js"></script>
    
    
    <script src="/blog/js/hux-blog.min.js"></script>
	
    
    
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/github.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/dockerfile.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/vim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/yaml.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/go.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/bash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/shell.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/nginx.min.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
</head>
</head>

<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Mashaoxun Blog</a>
        </div>

        
        
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/blog">Home</a>
                    </li>
                    
                    <li>
                        <a href="/blog/categories/django">django</a>
                    </li>
                    
                    <li>
                        <a href="/blog/categories/docker">docker</a>
                    </li>
                    
                    <li>
                        <a href="/blog/categories/k8s">k8s</a>
                    </li>
                    
                    <li>
                        <a href="/blog/categories/redis">redis</a>
                    </li>
                    
                    <li>
                        <a href="/blog/categories/swarm">swarm</a>
                    </li>
                    
                    <li>
                        <a href="/blog/categories/%E5%AD%98%E5%82%A8">存储</a>
                    </li>
                    
                    <li>
                        <a href="/blog/categories/%E7%9B%91%E6%8E%A7">监控</a>
                    </li>
                    
                    
		    
                        <li><a href="/blog/top/about/">ABOUT</a></li>
                    

                    
		    <li>
                        <a href="/blog/search">SEARCH <img src="/blog/img/search.png" height="15" style="cursor: pointer;"></a>
		    </li>
                    
                </ul>
            </div>
        </div>
        
    </div>
    
</nav>
<script>
    
    
    
    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        
            $navbar.className = " ";
            
            setTimeout(function(){
                
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>




<style type="text/css">
    header.intro-header {
        background-image: url('/blog/img/youyou.jpg')
    }
</style>
<header class="intro-header">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <div class="tags">
                        
                        <a class="tag" href="/blog/tags/docker" title="docker">
                            docker
                        </a>
                        
                        <a class="tag" href="/blog/tags/%E7%9B%91%E6%8E%A7" title="监控">
                            监控
                        </a>
                        
                    </div>
                    <h1>docker部署zabbix</h1>
                    <h2 class="subheading"></h2>
                    <span class="meta">
			Posted by 
			
			         &#34;马少勋&#34;
			 
			on 
			Tuesday, May 28, 2019
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>




<article>
    <div class="container">
        <div class="row">

            
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                post-container">

                
                <header>
                    <h2>TOC</h2>
                </header>
                <nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#服务信息与部署方式">服务信息与部署方式</a></li>
<li><a href="#部署流程">部署流程</a>
<ul>
<li><a href="#宿主机挂载目录创建">宿主机挂载目录创建：</a></li>
<li><a href="#docker方式创建zabbix-server组件">docker方式创建zabbix server组件</a></li>
<li><a href="#拷贝容器插件包到宿主机本地">拷贝容器插件包到宿主机本地</a></li>
<li><a href="#添加graphtree插件">添加graphtree插件</a></li>
<li><a href="#重新创建zabbix-web-nginx-mysql">重新创建zabbix-web-nginx-mysql</a></li>
<li><a href="#修改graphtree插件权限">修改graphtree插件权限</a></li>
<li><a href="#server本地的agent容器安装-特权模式">server本地的agent容器安装（特权模式）</a></li>
<li><a href="#页面修改">页面修改</a></li>
<li><a href="#中文字体库">中文字体库</a></li>
<li><a href="#添加企业微信报警脚本与python模块安装">添加企业微信报警脚本与python模块安装</a></li>
<li><a href="#其他宿主机的agent安装方式-保证防火墙开放">其他宿主机的agent安装方式（保证防火墙开放)</a></li>
</ul></li>
</ul></li>
</ul>
</nav>
                
                

<p><img src="http://www.mashaoxun.com/img/docker-zabbix-install01.png"  height="500" width="800">
<img src="http://www.mashaoxun.com/img/docker-zabbix-install02.png"  height="500" width="800"></p>

<h2 id="服务信息与部署方式">服务信息与部署方式</h2>

<p>zabbix版本Zabbix 4.2.1<br />
mysql，zabbix-server，zabbix-agent，nginx-web由docker部署。<br />
graphtree插件部署流程<br />
<a href="https://github.com/oneoaas/graphtrees">https://github.com/oneoaas/graphtrees</a></p>

<h2 id="部署流程">部署流程</h2>

<h3 id="宿主机挂载目录创建">宿主机挂载目录创建：</h3>

<p>（目录规划：/data/docker-mount/zabbixservice/{docker}/{in}/{dir}）</p>

<pre><code>/data/docker-mount/zabbixservice/zabbix-server-mysql/etc/zabbix
/data/docker-mount/zabbixservice/zabbix-server-mysql/usr/lib/zabbix/alertscripts
/data/docker-mount/zabbixservice/zabbix-web-nginx-mysql/usr/share/zabbix
</code></pre>

<h3 id="docker方式创建zabbix-server组件">docker方式创建zabbix server组件</h3>

<pre><code>mysql-server
docker run --name mysql-server -t -e MYSQL_DATABASE=&quot;zabbix&quot; -e MYSQL_USER=&quot;zabbix&quot; -e MYSQL_PASSWORD=&quot;zabbix_pwd&quot; -e MYSQL_ROOT_PASSWORD=&quot;root_pwd&quot; -e TZ=&quot;Asia/Shanghai&quot; -d mysql:5.7 --character-set-server=utf8 --collation-server=utf8_bin

zabbix-java-gateway
docker run --name zabbix-java-gateway -t -e TZ=&quot;Asia/Shanghai&quot; -d zabbix/zabbix-java-gateway:latest

zabbix-server-mysql
docker run --name zabbix-server-mysql -t -e DB_SERVER_HOST=&quot;mysql-server&quot; -e MYSQL_DATABASE=&quot;zabbix&quot; -e MYSQL_USER=&quot;zabbix&quot; -e MYSQL_PASSWORD=&quot;zabbix_pwd&quot; -e MYSQL_ROOT_PASSWORD=&quot;root_pwd&quot; -e ZBX_JAVAGATEWAY=&quot;zabbix-java-gateway&quot; -v /etc/localtime:/etc/localtime:ro -v /data/docker-mount/zabbixservice/zabbix-server-mysql/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts -v /data/docker-mount/zabbixservice/zabbix-server-mysql/etc/zabbix:/etc/zabbix --link mysql-server:mysql --link zabbix-java-gateway:zabbix-java-gateway -p 10051:10051 -d zabbix/zabbix-server-mysql:latest

zabbix-web-nginx-mysql
docker run --name zabbix-web-nginx-mysql -t -e DB_SERVER_HOST=&quot;mysql-server&quot; -e MYSQL_DATABASE=&quot;zabbix&quot; -e MYSQL_USER=&quot;zabbix&quot; -e MYSQL_PASSWORD=&quot;zabbix_pwd&quot; -e MYSQL_ROOT_PASSWORD=&quot;root_pwd&quot; --link mysql-server:mysql --link zabbix-server-mysql:zabbix-server -p 80:80 -d zabbix/zabbix-web-nginx-mysql:latest
</code></pre>

<h3 id="拷贝容器插件包到宿主机本地">拷贝容器插件包到宿主机本地</h3>

<p>进入到zabbix-web-nginx-mysql容器中</p>

<pre><code>打包/usr/share/zabbix/
拷贝docker cp e7a6a52f8074:/usr/share/zabbix.tgz /data/docker-mount/zabbixservice/zabbix-web-nginx-mysql/usr/share/zabbix
解压，替换zabbix目录
</code></pre>

<h3 id="添加graphtree插件">添加graphtree插件</h3>

<pre><code>cd /usr/share/zabbix
wget https://raw.githubusercontent.com/OneOaaS/graphtrees/master/graphtree3.0.4.patch
yum install -y patch
patch -Np0 &lt;graphtree3.0.4.patch
</code></pre>

<h3 id="重新创建zabbix-web-nginx-mysql">重新创建zabbix-web-nginx-mysql</h3>

<p>删除容器zabbix-web-nginx-mysql，并重新创建，添加挂载目录（包括容器中拷贝出来的插件以及graphtree插件）</p>

<pre><code>docker run --name zabbix-web-nginx-mysql -t     -e DB_SERVER_HOST=&quot;mysql-server&quot;       -e MYSQL_DATABASE=&quot;zabbix&quot;       -e MYSQL_USER=&quot;zabbix&quot;       -e MYSQL_PASSWORD=&quot;zabbix_pwd&quot;       -e MYSQL_ROOT_PASSWORD=&quot;root_pwd&quot;    -e PHP_TZ=&quot;Asia/Shanghai&quot;  --link mysql-server:mysql       --link zabbix-server-mysql:zabbix-server       -p 80:80 -v /etc/localtime:/etc/localtime:ro  -v  /data/docker-mount/zabbixservice/zabbix-web-nginx-mysql/usr/share/zabbix:/usr/share/zabbix       -d zabbix/zabbix-web-nginx-mysql:latest
</code></pre>

<h3 id="修改graphtree插件权限">修改graphtree插件权限</h3>

<pre><code>进入容器zabbix-web-nginx-mysql
chown -R nginx oneoaas
</code></pre>

<h3 id="server本地的agent容器安装-特权模式">server本地的agent容器安装（特权模式）</h3>

<pre><code>其中ZBX_SERVER_HOST的ip是zabbix-server-mysql的ip，ZBX_HOSTNAME是zabbix页面填写的主机名称
docker run --name server-zabbix-agent --link mysql-server:zabbix-server -e ZBX_SERVER_HOST=&quot;192.168.0.4&quot; -e ZBX_SERVER_PORT=10051 -e ZBX_HOSTNAME=&quot;server-zabbix-agent&quot; -e TZ=&quot;Asia/Shanghai&quot; -p 10050:10050 --privileged -d zabbix/zabbix-agent:latest
</code></pre>

<h3 id="页面修改">页面修改</h3>

<pre><code>zabbix页面修改agent的ip为容器server-zabbix-agent的ip地址（192.168.0.6）
</code></pre>

<h3 id="中文字体库">中文字体库</h3>

<pre><code>windows7 下的c:/windows/font/简体楷体 复制出来，默认名字叫simkai.ttf，
复制到宿主机的/usr/share/zabbix/fonts中，
修改 cat /usr/share/zabbix/include/defines.inc.php | grep FONT_NAME
define('ZBX_GRAPH_FONT_NAME', 'simkai'); // font file name
</code></pre>

<h3 id="添加企业微信报警脚本与python模块安装">添加企业微信报警脚本与python模块安装</h3>

<pre><code>zabbix-server-mysql容器将脚本复制到/usr/lib/zabbix/alertscripts路径下。
apk update &amp;&amp; apk add curl python
apk add --no-cache py-pip
pip install requests
</code></pre>

<h3 id="其他宿主机的agent安装方式-保证防火墙开放">其他宿主机的agent安装方式（保证防火墙开放)</h3>

<pre><code>其中ZBX_SERVER_HOST为server所在的宿主机公网ip地址，如果内网互通，就填写zabbix-server的内网ip地址。
docker run --name server-zabbix-agent -e ZBX_SERVER_HOST=&quot;118.190.82.38&quot; -e ZBX_SERVER_PORT=10051 -e ZBX_HOSTNAME=&quot;blog&quot; -p 10050:10050 --privileged -d zabbix/zabbix-agent:latest
</code></pre>


                
                
<div class="entry-shang text-center">
    
	    <p>「真诚赞赏，手留余香」</p>
	
	<button class="zs show-zs btn btn-bred">赞赏支持</button>
</div>
<div class="zs-modal-bg"></div>
<div class="zs-modal-box">
	<div class="zs-modal-head">
		<button type="button" class="close">×</button>
		<span class="author"><a href="https://masxhub.gitee.io/blog"><img src="/blog/img/favicon.png" />Mashaoxun Blog</a></span>
        
	        <p class="tip"><i></i><span>真诚赞赏，手留余香</span></p>
		
 
	</div>
	<div class="zs-modal-body">
		<div class="zs-modal-btns">
			<button class="btn btn-blink" data-num="2">2元</button>
			<button class="btn btn-blink" data-num="5">5元</button>
			<button class="btn btn-blink" data-num="10">10元</button>
			<button class="btn btn-blink" data-num="20">20元</button>
			<button class="btn btn-blink" data-num="50">50元</button>
			<button class="btn btn-blink" data-num="100">100元</button>
		</div>
		<div class="zs-modal-pay">
			<button class="btn btn-bred" id="pay-text">2元</button>
			<p>使用<span id="pay-type">微信</span>扫描二维码完成支付</p>
			<img src="/blog/img/reward/zanshang.jpg"  id="pay-image"/>
		</div>
	</div>
	<div class="zs-modal-footer">
		<label><input type="radio" name="zs-type" value="wechat" class="zs-type" checked="checked"><span ><span class="zs-wechat"><img src="/blog/img/reward/wechat-btn.png"/></span></label>
		<label><input type="radio" name="zs-type" value="alipay" class="zs-type" class="zs-alipay"><img src="/blog/img/reward/alipay-btn.png"/></span></label>
	</div>
</div>
<script type="text/javascript" src="/blog/js/reward.js"></script>

                

                <hr>
                <ul class="pager">
                    
                    <li class="previous">
                        <a href="2019/07/19/zabbix-del-hosts/" data-toggle="tooltip" data-placement="top" title="python脚本清理zabbix主机脚本">&larr;
                            Previous Post</a>
                    </li>
                    
                    
                    <li class="next">
                        <a href="/blog/post/2019-07-09-k8s-ns-and-svc-cmd/" data-toggle="tooltip" data-placement="top" title="python脚本批量执行k8s容器中的命令">Next
                            Post &rarr;</a>
                    </li>
                    
                </ul>

                
<div id="disqus-comment"></div>



            </div>
            
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                
                
                <section>
                    <hr class="hidden-sm hidden-xs">
                    <h5><a href="/tags/">FEATURED TAGS</a></h5>
                    <div class="tags">
                        
                        
                        
                        <a href="/blog/tags/ceph" title="ceph">
                            ceph
                        </a>
                        
                        
                        
                        
                        
                        <a href="/blog/tags/docker" title="docker">
                            docker
                        </a>
                        
                        
                        
                        <a href="/blog/tags/k8s" title="k8s">
                            k8s
                        </a>
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        <a href="/blog/tags/%E5%AD%98%E5%82%A8" title="存储">
                            存储
                        </a>
                        
                        
                        
                        <a href="/blog/tags/%E7%9B%91%E6%8E%A7" title="监控">
                            监控
                        </a>
                        
                        
                        
                        
                    </div>
                </section>
                

                
                
                <section>
                    <hr>
                    <h5>FRIENDS</h5>
                    <ul class="list-inline">
                        
                        <li><a target="_blank" href="http://www.zrq.org.cn">瑞卿博客</a></li>
                        
                    </ul>
                </section>
                
            </div>
        </div>
    </div>
</article>




<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                   
                    
                    <li>
                        <a href="mailto:youremail@gmail.com">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    
                    
                    
                    
                    

                    

		    
                    
                    <li>
                        <a target="_blank" href="/blog/img/404.jpeg">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-wechat fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    
                    
                    <li>
                        <a target="_blank" href="https://github.com/yourgithub">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    
                    
                    
                </ul>
		<p class="copyright text-muted">
                    Copyright &copy; Mashaoxun Blog , 2019
                    <br>
                    <a href="https://themes.gohugo.io/hugo-theme-cleanwhite">CleanWhite Hugo Theme</a> by <a href="https://zhaohuabing.com">Huabing</a> |
                    <iframe
                        style="margin-left: 2px; margin-bottom:-5px;"
                        frameborder="0" scrolling="0" width="100px" height="20px"
                        src="https://ghbtns.com/github-btn.html?user=zhaohuabing&repo=hugo-theme-cleanwhite&type=star&count=true" >
                    </iframe>
                </p>
            </div>
        </div>
    </div>
</footer>




<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>






<script>
    
    if($('#tag_cloud').length !== 0){
        async("/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>


<script>
    async("https://cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>


<script>
    (function(){
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https'){
       bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      }
      else{
      bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>







</body>
</html>
